 package nc.ui.mmpps.plo.action.busi;
 
 import java.awt.event.ActionEvent;
import javax.swing.KeyStroke;
import nc.itf.mmpps.plo.IAcePoQueryService;
import nc.ui.mmpps.plo.action.PloBusiActionParent;
import nc.ui.mmpps.plo.action.util.PoActionsUtil;
import nc.ui.mmpps.plo.dialog.PloBatchModifyDialog;
import nc.ui.mmpps.plo.model.PloManageAppModel;
import nc.ui.mmpps.plo.serviceproxy.PloClientServiceProxy;
import nc.ui.pubapp.uif2app.DefaultExceptionHanler;
import nc.ui.pubapp.uif2app.model.BillManageModel;
import nc.ui.uif2.IExceptionHandler;
import nc.ui.uif2.ShowStatusBarMsgUtil;
import nc.vo.mmpps.mpm.res.MpmRes;
import nc.vo.mmpps.mps0202.AggregatedPoVO;
import nc.vo.mmpps.mps0202.PoVO;
import nc.vo.pub.BusinessException;
import nc.vo.uif2.LoginContext;
 
 public class PloBatchModifyAction extends PloBusiActionParent
 {
   private static final long serialVersionUID = 1L;
   PloBatchModifyDialog batchModifyDialog;
   private String msg;
   
   public PloBatchModifyAction()
   {
     putValue("AcceleratorKey", KeyStroke.getKeyStroke(80, 8));
     putValue("ShortDescription", MpmRes.BTN_BATCHMODIFYK());
   }
   
 
 
   public void doAction(ActionEvent e)
     throws Exception
   {
     Object[] selObjects = getModel().getSelectedOperaDatas();
     
     PoVO[] pos = PoActionsUtil.convertObjects2PloVOs(selObjects);
     
     if (!checkBatchModify(pos)) {
       setMsg(MpmRes.getPloBatchEditExpt());
       exception();
       return;
     }
     
 
     if (1 == getBatchModifyDialog(pos[0].getPk_org()).showModal())
     {
       ShowStatusBarMsgUtil.showStatusBarMsg(MpmRes.getPloBatchSuccMsg(), getModel().getContext());
     }
     
     AggregatedPoVO[] aggs = AggregatedPoVO.constructAggPoVOs(pos);
     String[] ids = nc.vo.mmpps.plo.util.PloNumUtil.getCpoids(aggs);
     aggs = PloClientServiceProxy.getAcePoQueryService().queryByQueryForIDS(ids);
     getModel().directlyUpdate(aggs);
   }
   
   private void exception() {
     BusinessException e = new BusinessException();
     getExceptionHandler().handlerExeption(e);
   }
   
   public IExceptionHandler getExceptionHandler()
   {
     DefaultExceptionHanler handler = new DefaultExceptionHanler(getModel().getContext().getEntranceUI());
     if (exceptionHandler == null) {
       handler.setContext(getModel().getContext());
       handler.setErrormsg(getMsg());
     }
     return handler;
   }
   
 
 
   public String getMsg()
   {
     return msg;
   }
   
   public void setMsg(String msg) {
     this.msg = msg;
   }
   
 
 @Override
	protected boolean isActionEnable() {
		Object[] selObjs = ((PloManageAppModel) getModel()).getSelectedOperaDatas();
		//add by zhoufla 20181008
		boolean unConfirm = true;
		if (selObjs != null && selObjs.length > 0) {
			PoVO[] allPoVOs = PoActionsUtil.convertObjects2PloVOs(selObjs);
			for (int i = 0; i < selObjs.length; i++) {
				PoVO poVO = allPoVOs[i];
				if (poVO.getFbillstatus() != 0) {
					unConfirm = false;
				}
			}
		}//end by zhoufla 
		return super.isActionEnable() && unConfirm;
	}
 
 
 
   private boolean checkBatchModify(PoVO[] povo)
   {
     String pk_org = povo[0].getPk_org();
     String pk_group = povo[0].getPk_group();
     for (int i = 1; i < povo.length; i++) {
       if ((!pk_org.equals(povo[i].getPk_org())) || (!pk_group.equals(povo[i].getPk_group())))
       {
 
         return false; }
     }
     return true;
   }
   
   public String getBtnCode()
   {
     return "BatchModifyAction";
   }
   
   public String getBtnName()
   {
     return MpmRes.BTN_BATCHMODIFY();
   }
   
   public PloBatchModifyDialog getBatchModifyDialog(String pk_org) {
     if (batchModifyDialog != null) {
       batchModifyDialog = null;
       System.gc();
     }
     batchModifyDialog = new PloBatchModifyDialog(getModel(), MpmRes.BTN_BATCHMODIFY());
     batchModifyDialog.setPk_org(pk_org);
     return batchModifyDialog;
   }
 }

